﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
namespace DalatCooking.Core.Helper
{
    public class MailModels
    {
        public MailMessage MailMsg { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Host { get; set; }
        public int Port { get; set; }
        public bool UseDefaultCredentials { get; set; }
        public bool EnableSsl { get; set; }
        public MailModels() { }
        public MailModels(MailMessage MailMsg, string UserName, string Password, string Host, int Port, bool UseDefaultCredentials, bool EnableSsl)
        {
            this.MailMsg = MailMsg;
            this.UserName = UserName;
            this.Password = Password;
            this.Host = Host;
            this.Port = Port;
            this.UseDefaultCredentials = UseDefaultCredentials;
            this.EnableSsl = EnableSsl;
        }
    }

    public class MailServices
    {
        public static bool Send(MailModels m)
        {
            try
            {
                SmtpClient smtp = new SmtpClient();
                m.MailMsg.IsBodyHtml = true;
                m.MailMsg.Priority = MailPriority.High;
                smtp.UseDefaultCredentials = m.UseDefaultCredentials;
                smtp.Credentials = new System.Net.NetworkCredential(m.UserName, m.Password);
                smtp.EnableSsl = m.EnableSsl;
                smtp.Host = m.Host;
                smtp.Port = m.Port;
                smtp.Send(m.MailMsg);
                return true;
            }
            catch (SmtpException ex)
            {
                throw ex;
            }
        }
    }
}
